#ifndef ROHELPER_H
#define ROHELPER_H

#include <QObject>
#include <QUrl>
#include <QQmlComponent>

#include "ROHost.h"
#include "RONode.h"
#include "ROTriggeredUpdater.h"
#include "ROFramedUpdater.h"

class ROHelper:public QObject
{
    Q_OBJECT
    QML_NAMED_ELEMENT(ROHelper)
    QML_SINGLETON
public:

    static ROHelper* instance();

    //通过组件创建一个对象，组件和parent必须是已经注册过的远程对象
    Q_INVOKABLE QObject* createObjectFromComponent(QQmlComponent* comp,const QVariantMap& param = {});

    Q_INVOKABLE QObject* createObjectFromUrl(QObject* parent,QUrl source,const QVariantMap& param = {});

    //从已知对象身上找到对应的Host或Node
    Q_INVOKABLE ROHost* getHost(QObject* obj);
    Q_INVOKABLE RONode* getNode(QObject* obj);

    Q_INVOKABLE void removeBinding(QObject* obj,QString property);

    ROHelper();
    ~ROHelper();
    ROTriggeredUpdater *triggered();
    ROFramedUpdater *framed();
private:

    QHash<QUrl,QQmlComponent*> m_comps;
    ROTriggeredUpdater* m_triggered = nullptr;
    ROFramedUpdater* m_framed = nullptr;

    Q_PROPERTY(ROTriggeredUpdater *triggered READ triggered CONSTANT)
    Q_PROPERTY(ROFramedUpdater *framed READ framed CONSTANT)
};

#endif
